#ifndef _DWMRICORE_TWOTENSOR_H
#define _DWMRICORE_TWOTENSOR_H

#include "Point3F.h"
#include "defines.h"

#include <stdlib.h>

// TEEM
#include <teem/nrrd.h>
#include <teem/biff.h>

/************************************************/
/* data in m_pTwoTensor: flag TenA flag TenB	*/
/************************************************/
class CTwoTensor
{
public:
	float *m_pTwoTensor;
	uint m_w;
	uint m_h;
	uint m_d;
	uint m_n;			// should always be 14

public:
	CTwoTensor(void);
	~CTwoTensor(void);

public:
	// open the Two Tensor in Nrrd format
	int OpenTwoTensorFile(const char *pathname, FILE *fp = stdout);
	// save the Two Tensor as Nrrd format
	int SaveTwoTensorFile(const char *pathname, FILE *fp = stdout);		

	// return the pointer of the DTI data
	float *GetTwoTensorData() { return m_pTwoTensor; }

	void GetTwoTensor(const uint x, const uint y, const uint z, float *twoTensor) const;
	void GetTwoTensor(const uint index, float *twoTensor) const;
	void GetTensorA(const uint x, const uint y, const uint z, float *ten) const;
	void GetTensorA(const uint index, float *ten) const;
	void GetTensorB(const uint x, const uint y, const uint z, float *ten) const;
	void GetTensorB(const uint index, float *ten) const;

	uint GetWidth() const { return m_w; }
	uint GetHeight() const { return m_h; }
	uint GetDepth() const { return m_d; }
	uint GetN() const { return m_n; }

	bool HasData() { 
		if (m_pTwoTensor) {
			return true; 
		} else {
			return false;
		}
	}

	void Tensor2Direction(const float *dti, CVector3F *dir) const;
	float Tensor2FA(const float *dti) const;
};

#endif